******************************************************************
* Code to produce figures and tables in Kargar and Mann (RFS 2022)
* This code will look for the following input files (all are included with the replication archive):
*  ./Data/IPEDS/IPEDS.dta
*	This is a 2021 vintage of IPEDS, with slight cleanup and formatting.
*	Used for Appendix Figures B1 and B2, and Table B1.
*  ./Data/TitleIV/TitleIV.dta
*	This is a 2021 vintage of Title IV data, with slight cleanup and formatting.
*	Used for Figures 3 and 4.
*  ./Data/Pell_Grants/Pell_Grant.csv
*	This is a 2021 vintage of data on Pell recipients and disbursements.
*	Used for Figures 3 and 4.
*  ./Data/IPEDS_TitleIV_merged.dta
*	Merged version of the above datasets.
*	Used for everything other than the figures and tables mentioned above.
*	The merge is performed in a separate file merge.do,
*	which is also bundled in the archive and can be used to reconstruct the merged dataset,
*	but first one needs to copy the included file statecode.ado into the appropriate directory where Stata can find it
*	(e.g. ~/ado for Linux, c:\ado for Windows)
******************************************************************

clear all
set more off

*************************************************************
* Save lists of the components of IPEDS revenues and expenses
*************************************************************

	local revenue_vars tuition_fees auxent_revenue fedl_apgtcx pvgifts_grants_contracts statelocal_apgtcx educational_sales hospital_revenue affiliate_contributions investment_return independent_ops_revenue other_revenue
	local expense_vars instrl_expense support_expense auxent_expense rsrch_svc_expense hospsvc_expense netgrantaid_expense plant_expense indops_expense other_expense 

*********************************************************
* Build the sample used in most of the figures and tables
*********************************************************
	
	* Import the merged IPEDS and Title IV data.
		use ./Data/IPEDS_TitleIV_merged, clear
		xtset opeid6 awardyear

	** Filters described in the paper:
	
	* Keep only observations with nonmissing data for our outcome variables
		* Advertised tuition:
		drop if ln(chg1ay3) == .
		* Enrollment:
		drop if ln(cdactua) == . | ln(efytotlt) == . 
		* Financial:
		drop if ln(total_revenues) == . | ln(total_expenses) == .

	* Keep only schools with at least 1000 students in 2010
		preserve
			keep if awardyear == 2010
			isid opeid6
			drop if efytotlt < 1000
			keep opeid6 
			tempfile efytotlt1000
			save `efytotlt1000'
		restore
		merge m:1 opeid6 using `efytotlt1000', nogen keep(3)
		xtset opeid6 awardyear

	* Keep only schools that appear in 2010, 2011, and 2012 after the above filters
		preserve
			keep if inlist(awardyear,2010,2011,2012)
			bysort opeid6: keep if _N == 3
			bysort opeid6: keep if _n == 1
			keep opeid6
			tempfile sample
			save `sample'
		restore
		merge m:1 opeid6 using `sample', nogen keep(3)

	** Cleaning and rescaling the data

	* Fix for-profit status and state of location based on 2010
		preserve
			keep if awardyear == 2010
			isid opeid6
			keep opeid6 forprofit state
			tempfile forprofit
			save `forprofit'
		restore
		drop forprofit state
		merge m:1 opeid6 using `forprofit', nogen keep(3)
		xtset opeid6 awardyear

	* Scale financial variables by $1000
		foreach var of varlist ugrad_volloans ugrad_plus_volloans pell_disbursements chg1ay3 total_revenues total_expenses `revenue_vars' `expense_vars' {
			replace `var' = `var' / 1e3
		}

	* Create some new variables and ratios for later use.
		* Investment income as a fraction of total revenues
		g investment_ratio = investment_return / total_revenues
		* Title IV loans as a share of total revenues
		g loans_ratio = ugrad_volloans / total_revenues
		* Total revenues net of investment revenues
		g rev_x_inv = total_revenues - investment_return
		* Undergraduate FTEs
		g fteug = cdactua / 30
		* Per-FTE quantities
		foreach var of varlist total_revenues total_expenses rev_x_inv tuition_fees {
			g `var'_fteug = `var' / fteug
		}
		* Per-student quantities
		foreach var of varlist ugrad_plus_numreps rev_x_inv {
			g `var'_efytotlt = `var' / efytotlt
		}
		* Shares of each revenue category in non-investment revenues
		foreach var of varlist `revenue_vars' {
			g `var'_s = `var' / rev_x_inv
		}
		* Shares of each expense category in total expenses
		foreach var of varlist `expense_vars' {
			g `var'_s = `var' / total_expenses
		}
		* Log and differenced variables.
		foreach var of varlist ugrad_plus_numreps ugrad_plus_volloans chg1ay3 efytotlt fteug total_revenues tuition_fees total_expenses rev_x_inv pell_recipients pell_disbursements instrl_expense auxent_expense support_expense {
			g ln_`var' = ln(`var')
			g d_`var' = d.`var'
			g d_ln_`var' = d.ln_`var'
		}
		* Save 2010 values of the exposure measure for the natural experiment, and copy them to every year:
		preserve
			keep if awardyear == 2010
			isid opeid6
			g frac_low_income_2010 = frac_low_income
			* Create four bins of exposure:
			xtile fp4 = frac_low_income_2010, nq(4)
			* Recode the bin numbering to start with 0 instead of 1
			replace fp4 = fp4 - 1
			keep opeid6 fp4 *_2010
			tempfile treatment
			save `treatment'
		restore
		merge m:1 opeid6 using `treatment', nogen keep(3)
		xtset opeid6 awardyear
		* After and treatment-after indicators
		g after = awardyear > 2010
		g frac_low_income_2010_after = frac_low_income_2010*after
		* State-year interaction terms.
		egen state_year = group(state awardyear)

		tempfile regression_sample
		save `regression_sample'

***************************************************************
* Table 1: Summary statistics for our regression sample
***************************************************************

	* Import the dataset created earlier
		use `regression_sample', clear
		xtset opeid6 awardyear

	* Save the ``as of 2010'' outcomes
	drop frac_low_income_2010
 	local asof2010 chg1ay3 rev_x_inv_fteug total_expenses_fteug investment_ratio loans_ratio ugrad_plus_numreps_efytotlt frac_low_income forprofit
	preserve
		keep if awardyear == 2010
		keep opeid6 awardyear `asof2010'
		foreach var of varlist `asof2010' {
			rename `var' `var'_2010
		}
		tempfile asof2010
		save `asof2010'
	restore
	merge 1:1 opeid6 awardyear using `asof2010' , nogen
	
	* Label variables
		label variable ugrad_plus_numreps "PLUS Loan Recipients"
		label variable ugrad_plus_volloans "PLUS Loan Volume (\$ \\\\$ 1000\$)"
		label variable efytotlt "Undergraduate 12-month headcount"
		label variable fteug "Undergraduate FTEs"
		label variable total_revenues "Total revenues (\$\\\\$ 1000\$)"
		label variable rev_x_inv "Non-investment revenues (\$\\\\$ 1000\$)"
		label variable total_expenses "Total expenses (\$\\\\$ 1000\$)"

		label variable d_ln_ugrad_plus_numreps "$\Delta$\-Ln(PLUS Loan Recipients)"
		label variable d_ln_ugrad_plus_volloans "$\Delta$\-Ln(PLUS Loan Volume)"
		label variable d_ln_efytotlt "$\Delta$\-Ln(Undergraduate 12-month headcount)"
		label variable d_ln_fteug "$\Delta$\-Ln(Undergraduate FTEs)"
		label variable d_ln_chg1ay3 "$\Delta$\-Ln(Advertised tuition and fees)"
		label variable d_ln_rev_x_inv "$\Delta$\-Ln(Non-investment revenue)"
		label variable d_ln_total_expenses "$\Delta$\-Ln(Total expenses)"

		label variable chg1ay3_2010 "\quad Advertised tuition and fees (\$\\\\$ 1000\$)"
		label variable investment_ratio_2010 "\quad Investment income / total revenues"
		label variable loans_ratio_2010 "\quad Federal student loans / total revenues"
		label variable rev_x_inv_fteug_2010 "\quad Non-investment revenues / UFTEs (\$\\\\$ 1000\$)"
		label variable total_expenses_fteug_2010 "\quad Total expenses / UFTEs (\$\\\\$ 1000\$)"
		label variable ugrad_plus_numreps_efytotlt_2010 "\quad Fraction of students receiving PLUS loans"
		label variable frac_low_income_2010 "\quad Frac of aid recipients less than \$ \\\\$ 48\$~k income" // (F\\textsubscript{i,2010})"
		label variable forprofit_2010 "\quad For-profit"

	* Save the list of summary statistics to display. The "hline" and "asof2010" are hacks to add those things to the table.
		local sumvars ///
			ugrad_plus_numreps ugrad_plus_volloans efytotlt fteug total_revenues rev_x_inv total_expenses ///
			hline ///
			d_ln_ugrad_plus_numreps d_ln_ugrad_plus_volloans d_ln_efytotlt d_ln_fteug d_ln_chg1ay3 d_ln_rev_x_inv d_ln_total_expenses ///
			hline asof2010 ///
			chg1ay3_2010 investment_ratio_2010 loans_ratio_2010 ///
			rev_x_inv_fteug_2010 total_expenses_fteug_2010 ugrad_plus_numreps_efytotlt_2010 frac_low_income_2010 forprofit_2010

	* Build the table of summary statistics (using external calls to Bash shell)
		!echo "\begin{tabular}{l c c c c c c}" > ./Tables/Table1.tex
		!echo "\toprule Variable description & Obs & Q25 & Median & Q75 & Mean & Std dev \\\\ \hline \\\\[-1.8ex]" >> ./Tables/Table1.tex
		foreach compvar in `sumvars' {
			if "`compvar'" == "hline" {
				!echo "\hline \\\\[-1.8ex] " >> ./Tables/Table1.tex
				continue
			}
			if "`compvar'" == "asof2010" {
				!echo "As of 2010: \\\\ " >> ./Tables/Table1.tex	
				continue
			}
			quiet sum `compvar', detail
			local p25 = r(p25)
			local median = r(p50)
			local mean = r(mean)
			local p75 = r(p75)
			local sd = r(sd)
			local N = r(N)
			if regexm("`compvar'","ln|_ratio|_fteug|_efytotlt|frac_|chg1ay3|_s|forprofit") local displayformat "%10.3fc"
			else local displayformat "%10.0fc"
			!echo "`:var label `compvar'' & `:di %10.0fc `N'' & `:di `displayformat' `p25'' & `:di `displayformat' `median'' & `:di `displayformat' `p75'' & `:di `displayformat' `mean'' & `:di `displayformat' `sd'' \\\\" >> ./Tables/Table1.tex
		}
		!echo "\bottomrule \end{tabular}" >> ./Tables/Table1.tex

**********************************************************
* Figures 1 and 2: 
* Growth in revenues, expenses, and tuition in our sample
**********************************************************

	* Import the dataset created earlier.
		use `regression_sample', clear
		xtset opeid6 awardyear

	* Restrict to 2008-2016.
		keep if inrange(awardyear,2008,2018)

	* Calculate aggregate revenues, aggregate expenses, median revenues/FTEs, median expenses/FTEs, and median advertised tuition.
		foreach var of varlist total_revenues rev_x_inv total_expenses tuition_fees {
			bysort awardyear: egen agg_`var' = sum(`var')
			* Rescale aggregate values to billions: They were already in thousands, so divide by 1m.
			replace agg_`var' = agg_`var' / 1e6 
			bysort awardyear: egen median_`var'_fteug = median(`var'_fteug)
		}
		bysort awardyear: egen median_tuition = median(chg1ay3) 
		keep awardyear agg_* median_*

	* Keep one observation per year.
		bysort awardyear: keep if _n == 1

	* Construct the figures.
	line agg_rev_x_inv agg_total_expenses awardyear ///
		, ///
		graphregion(color(white)) ///
		legend(order(1 "Total revenues, net of investment income" 2 "Total expenses") rows(2)) ///
		xtitle("Award year") ///
		ytitle("$ billions") ylabel(,nogrid) ///
		lpattern(solid dash dash_dot dot) lcolor(black black black black)
	graph export ./Figures/Figure1.eps, replace
	line median_tuition median_rev_x_inv_fteug median_total_expenses_fteug awardyear ///
		, ///
		graphregion(color(white)) ///
		legend(order(1 "Advertised tuition" 2 "Total revenues, net of investment income, per FTE" 3 "Total expenses per FTE" ) rows(3)) ///
		xtitle("Award year") ///
		ytitle("$ thousands") ///
		ylabel(15 20 25 30 35, nogrid) ///
		lpattern(solid longdash dot) lcolor(black black black)
	graph export ./Figures/Figure2.eps, replace

****************************************************************
* Figures 3 and 4:
* Aggregate and average volumes of loan programs and Pell grants
****************************************************************

	insheet using ./Data/Pell_Grants/Pell_Grant.csv, clear
	rename award_year awardyear
	foreach var of varlist pell_disbursements pell_recipients {
		replace `var'  = "" if `var' == "NA"
		destring `var', replace
	}
	keep if inrange(awardyear,2010,2018)
	bysort awardyear: egen agg_pell_volume = sum(pell_disbursements)
	bysort awardyear: egen agg_pell_recipients = sum(pell_recipients)
	g avg_pell_amount = agg_pell_volume / agg_pell_recipients
	keep awardyear agg_pell_volume avg_pell_amount
	by awardyear: keep if _n == 1
	tempfile Pell
	save `Pell'
	
	use awardyear ///
		DL_ugrad_subs_volloans DL_ugrad_subs_numreps ///
		DL_ugrad_unsubs_volloans DL_ugrad_unsubs_numreps ///
		DL_ugrad_plus_volloans DL_ugrad_plus_numreps ///
		using ./Data/TitleIV/TitleIV ///
		if inrange(awardyear,2010,2018) ///
		, clear
	foreach prgm in subs unsubs plus {
		bysort awardyear: egen agg_`prgm'_volume = sum(DL_ugrad_`prgm'_volloans)
		bysort awardyear: egen agg_`prgm'_recipients = sum(DL_ugrad_`prgm'_numreps)
		g avg_`prgm'_amount = agg_`prgm'_volume / agg_`prgm'_recipients
	}
	keep awardyear agg_*_volume avg_*_amount
	by awardyear: keep if _n == 1
	merge 1:1 awardyear using `Pell'
	
	foreach prgm in pell subs unsubs plus {
		replace agg_`prgm'_volume = agg_`prgm'_volume / 1e9
	}
	
	* Aggregates:
	graph bar agg_pell_volume agg_subs_volume agg_unsubs_volume agg_plus_volume, ///
		graphregion(color(white)) ///
		over(awardyear) ///
		stack ///
		ylabel(0 25 50 75 100) ///
		ytitle("Volume ($ billions)", height(7)) ///
		bar(1, color(gs13)) ///
		bar(2, color(gs11))  ///
		bar(3, color(gs9 ))  ///
		bar(4, color(gs4 )) ///
		legend(order(4 "PLUS" 3 "Unsubsidized" 2 "Subsidized" 1 "Pell") rows(1) region(lcolor(white)) )
	graph export ./Figures/Figure3.eps, replace
	
	* Averages:
	line avg_pell_amount avg_subs_amount avg_unsubs_amount avg_plus_amount awardyear, ///
		graphregion(color(white)) ///
		ylabel(0 4000 8000 12000 16000, ang(h)) ///
		xtitle("Award year") ///
		ytitle("Average borrowing ($)", height(7)) ///
		lcolor( gs13 gs11 gs9 gs4 ) ///
		lwidth(medthick medthick medthick medthick) ///
		legend(order(4 "PLUS" 3 "Unsubsidized" 2 "Subsidized" 1 "Pell") rows(1) region(lcolor(white)) )
	graph export ./Figures/Figure4.eps, replace

**************************************************************************
* Figures 5 through 8:
* Parallel trends for the main outcome variables in the natural experiment 
**************************************************************************

	* Import the dataset created earlier.
		use `regression_sample', clear
		xtset opeid6 awardyear

	* Restrict to 2007-2013.
		keep if inrange(awardyear,2007,2013)

	* Set 2010 as the reference year for the regressions.
		char awardyear[omit] 2010

	* Run the regressions and construct the figures.
	foreach outcome in d_ln_ugrad_plus_numreps d_ln_ugrad_plus_volloans d_ln_fteug d_ln_efytotlt {

		* This is our main specification from the natural experiment.
		xi: reg `outcome' i.awardyear*frac_low_income_2010, cluster(opeid6)

		* Save all coefficients and standard errors. (Skip 2010, has no coefficient because it was the reference year.)
		forvalues awardyear = 2007/2013 {
			if `awardyear' == 2010 continue
			local  b_`awardyear' =  _b[_IawaXfra_`awardyear']
			local se_`awardyear' = _se[_IawaXfra_`awardyear']
		}

		* Create a dataset with just a list of years, coefficients, and confidence intervals.
		preserve
		clear
		set obs `:di 2013 - 2007 + 1'
		g awardyear = _n + 2006
		g b = .
		g b_up = .
		g b_dn = .
		forvalues awardyear = 2007/2013 {
			if `awardyear' == 2010 continue
			replace b = `b_`awardyear'' if awardyear == `awardyear'
			replace b_up = `b_`awardyear''+2.58*`se_`awardyear'' if awardyear == `awardyear'
			replace b_dn = `b_`awardyear''-2.58*`se_`awardyear'' if awardyear == `awardyear'
		}

		* Save the figure.
		line b b_up b_dn awardyear , ///
			graphregion(color(white)) legend(off) ///
			lpattern(solid dash dash) lcolor(black black black) ///
			ytitle("Coefficient relative to 2010") yline(0, lcolor(gs8)) ///
			cmissing(no no no) ///
			xtitle("Academic year") xscale(range(2007 2013)) xlabel(2007(1)2013)
		if "`outcome'" == "d_ln_ugrad_plus_numreps"	graph export ./Figures/Figure5.eps, replace
		if "`outcome'" == "d_ln_ugrad_plus_volloans"	graph export ./Figures/Figure6.eps, replace
		if "`outcome'" == "d_ln_fteug"			graph export ./Figures/Figure7.eps, replace
		if "`outcome'" == "d_ln_efytotlt"		graph export ./Figures/Figure8.eps, replace
		restore
	}

**********************************************************
* Regression tables
**********************************************************

	* Import the dataset created earlier; restrict to 2007--2013
		use `regression_sample' if inrange(awardyear,2007,2013), clear
		xtset opeid6 awardyear

	* OLS regressions in Section 2:

	* Table 2, Panel (a)
		eststo clear
	xi: reg rev_x_inv fteug, cluster(opeid6)
		eststo
	xi: reg total_expenses fteug, cluster(opeid6)
		eststo
	xi: reg ln_rev_x_inv ln_fteug, cluster(opeid6)
		eststo
	xi: reg ln_total_expenses ln_fteug, cluster(opeid6)
		eststo
	esttab using ./Tables/Table2a.tex, replace ///
		star(* 0.05 ** 0.01 *** 0.001) ///
		noomitted ///
		style(tex) ///
		booktabs ///
		se ///
        	stats(r2 N, labels("$ R^2$" "Obs.")) ///
		mtitles(Revenues Expenses Ln(Revenues) Ln(Expenses)) ///
		eqlabels(none) ///
		keep(fteug ln_fteug _cons) ///
		varlabels(	fteug "UFTEs" ///
				ln_fteug "Ln(UFTEs)" ///
				_cons "Constant" )

	* Table 2, Panel (b)
		eststo clear
	xi: reg d_rev_x_inv d_fteug, cluster(opeid6)
		eststo
	xi: reg d_total_expenses d_fteug, cluster(opeid6)
		eststo
	xi: reg d_ln_rev_x_inv d_ln_fteug, cluster(opeid6)
		eststo
	xi: reg d_ln_total_expenses d_ln_fteug, cluster(opeid6)
		eststo
	esttab using ./Tables/Table2b.tex, replace ///
		star(* 0.05 ** 0.01 *** 0.001) ///
		noomitted ///
		style(tex) ///
		booktabs ///
		se ///
        	stats(r2 N, labels("$ R^2$" "Obs.")) ///
		mtitles($\Delta$\-Revenues $\Delta$\-Expenses $\Delta$\-Ln(Revenues) $\Delta$\-Ln(Expenses)) ///
		eqlabels(none) ///
		keep(d_fteug d_ln_fteug _cons) ///
		varlabels(	d_fteug "$\Delta$\-UFTEs" ///
				d_ln_fteug "$\Delta$\-Ln(UFTEs)" ///
				_cons "Constant" )

	* Natural experiment results:

	* Set 2010 as the reference year for the regressions.
		char awardyear[omit] 2010

	* Table 3
		eststo clear
	xi: reg d_ln_ugrad_plus_numreps i.after*frac_low_income_2010, cluster(opeid6)
		eststo
	xi: reg d_ln_ugrad_plus_volloans i.after*frac_low_income_2010, cluster(opeid6)
		eststo
	xi: reg d_ln_ugrad_plus_numreps i.fp4*i.after, cluster(opeid6)
		eststo
	xi: reg d_ln_ugrad_plus_volloans i.fp4*i.after, cluster(opeid6)
		eststo
	esttab using ./Tables/Table3.tex, replace ///
		star(* 0.05 ** 0.01 *** 0.001) ///
		noomitted ///
		booktabs ///
		se ///
        	stats(r2 N, labels("$ R^2$" "Obs.")) ///
		mtitles($\Delta$\-Ln(PLUS~num) $\Delta$\-Ln(PLUS~vol) $\Delta$\-Ln(PLUS~num) $\Delta$\-Ln(PLUS~vol)) ///
		eqlabels(none) ///
		order(_IaftXfrac__1 frac_low_income_2010 _Ifp4X* _Ifp4_* _Iafter_1 _cons ) ///
		varlabels(	_IaftXfrac__1 "Fraction $\times$ After" ///
				frac_low_income_2010 "Fraction" ///
				_Ifp4Xaft_1_1 "Bin 2/4 $\times$ After" ///
				_Ifp4Xaft_2_1 "Bin 3/4 $\times$ After" ///
				_Ifp4Xaft_3_1 "Bin 4/4 $\times$ After" ///
				_Ifp4_1 "Bin 2/4" ///
				_Ifp4_2 "Bin 3/4" ///
				_Ifp4_3 "Bin 4/4" ///
				_Iafter_1 "After" ///
				_cons "Constant" )

	* Table 4
		eststo clear
	xi: reg d_ln_efytotlt i.after*frac_low_income_2010, cluster(opeid6)
		eststo
	xi: reg d_ln_fteug i.after*frac_low_income_2010, cluster(opeid6)
		eststo
	xi: reg d_ln_efytotlt i.fp4*i.after, cluster(opeid6)
		eststo
	xi: reg d_ln_fteug i.fp4*i.after, cluster(opeid6)
		eststo
	esttab using ./Tables/Table4.tex, replace ///
		star(* 0.05 ** 0.01 *** 0.001) ///
		noomitted ///
		booktabs ///
		se ///
        	stats(r2 N, labels("$ R^2$" "Obs.")) ///
		mtitles($\Delta$\-Ln(Headcount) $\Delta$\-Ln(UFTEs) $\Delta$\-Ln(Headcount) $\Delta$\-Ln(UFTEs)) ///
		eqlabels(none) ///
		order(_IaftXfrac__1 frac_low_income_2010 _Ifp4X* _Ifp4_* _Iafter_1 _cons ) ///
		varlabels(	_IaftXfrac__1 "Fraction $\times$ After" ///
				frac_low_income_2010 "Fraction" ///
				_Ifp4Xaft_1_1 "Bin 2/4 $\times$ After" ///
				_Ifp4Xaft_2_1 "Bin 3/4 $\times$ After" ///
				_Ifp4Xaft_3_1 "Bin 4/4 $\times$ After" ///
				_Ifp4_1 "Bin 2/4" ///
				_Ifp4_2 "Bin 3/4" ///
				_Ifp4_3 "Bin 4/4" ///
				_Iafter_1 "After" ///
				_cons "Constant" )

	* Table 5
		eststo clear
	xi: reg d_ln_rev_x_inv i.after*frac_low_income_2010, cluster(opeid6)
		eststo
	xi: reg d_ln_total_expenses i.after*frac_low_income_2010, cluster(opeid6)
		eststo
	xi: reg d_ln_rev_x_inv i.fp4*i.after, cluster(opeid6)
		eststo
	xi: reg d_ln_total_expenses i.fp4*i.after, cluster(opeid6)
		eststo
	esttab using ./Tables/Table5.tex, replace ///
		star(* 0.05 ** 0.01 *** 0.001) ///
		noomitted ///
		booktabs ///
		se ///
        	stats(r2 N, labels("$ R^2$" "Obs.")) ///
		mtitles($\Delta$\-Ln(Revenues) $\Delta$\-Ln(Expenses) $\Delta$\-Ln(Revenues) $\Delta$\-Ln(Expenses)) ///
		eqlabels(none) ///
		order(_IaftXfrac__1 frac_low_income_2010 _Ifp4X* _Ifp4_* _Iafter_1 _cons ) ///
		varlabels(	_IaftXfrac__1 "Fraction $\times$ After" ///
				frac_low_income_2010 "Fraction" ///
				_Ifp4Xaft_1_1 "Bin 2/4 $\times$ After" ///
				_Ifp4Xaft_2_1 "Bin 3/4 $\times$ After" ///
				_Ifp4Xaft_3_1 "Bin 4/4 $\times$ After" ///
				_Ifp4_1 "Bin 2/4" ///
				_Ifp4_2 "Bin 3/4" ///
				_Ifp4_3 "Bin 4/4" ///
				_Iafter_1 "After" ///
				_cons "Constant" )

	* Winsorize the growth rate of advertised tuition
		quiet sum d_ln_chg1ay3, detail
		replace d_ln_chg1ay3 = r(p1) if d_ln_chg1ay3 < r(p1)
		replace d_ln_chg1ay3 = r(p99) if d_ln_chg1ay3 > r(p99) & d_ln_chg1ay3 < .
	* Table 6
		eststo clear
	xi: reg d_ln_chg1ay3 i.after*frac_low_income_2010, cluster(opeid6)
		eststo
		estadd local FixedEffect "None"
	xtset state_year
	xi: xtreg d_ln_chg1ay3 i.after*frac_low_income_2010, fe robust
		eststo
		estadd local FixedEffect "State-year"
	xtset opeid6 awardyear
	xi: xtreg d_ln_chg1ay3 i.after*frac_low_income_2010, fe robust
		eststo
		estadd local FixedEffect "College"
	esttab using ./Tables/Table6.tex, replace ///
		star(* 0.05 ** 0.01 *** 0.001) ///
		noomitted ///
		booktabs ///
		se ///
        	stats(FixedEffect r2 N, labels("Fixed Effect" "$ R^2$" "Obs.")) ///
		mtitles($\Delta$\-Ln(Tuition) $\Delta$\-Ln(Tuition) $\Delta$\-Ln(Tuition) $\Delta$\-Ln(Tuition)) ///
		eqlabels(none) ///
		order(_IaftXfrac__1 frac_low_income_2010 _Iafter_1 _cons ) ///
		varlabels(	_IaftXfrac__1 "Fraction $\times$ After" ///
				frac_low_income_2010 "Fraction" ///
				_Iafter_1 "After" ///
				_cons "Constant" )

	* Table 7
		eststo clear
	xi: ivreg2 d_ln_total_expenses (d_ln_fteug = frac_low_income_2010_after) frac_low_income_2010 after, cluster(opeid6)
		eststo
		estadd local FixedEffect "None"
	xi: xtivreg2 d_ln_total_expenses (d_ln_fteug = frac_low_income_2010_after) frac_low_income_2010 after, fe robust
		eststo
		estadd local FixedEffect "College"
	xtset state_year
	xi: xtivreg2 d_ln_total_expenses (d_ln_fteug = frac_low_income_2010_after) frac_low_income_2010 after, fe robust
		eststo
		estadd local FixedEffect "State-year"
	xtset opeid6 awardyear
	esttab using ./Tables/Table7.tex, replace ///
		star(* 0.05 ** 0.01 *** 0.001) ///
		noomitted ///
		booktabs ///
		se ///
        	stats(FixedEffect N, labels("Fixed Effect" "Obs.")) ///
		mtitles($\Delta$\-Ln(Expenses) $\Delta$\-Ln(Expenses) $\Delta$\-Ln(Expenses)) ///
		eqlabels(none) ///
		keep(d_ln_fteug) ///
		varlabels(	d_ln_fteug "$\Delta$\-Ln(UFTEs)" )

	* Table 8
		eststo clear
	xi: ivreg2 d_ln_rev_x_inv (d_ln_fteug = frac_low_income_2010_after) frac_low_income_2010 after, cluster(opeid6)
		eststo
		estadd local FixedEffect "None"
	xi: xtivreg2 d_ln_rev_x_inv (d_ln_fteug = frac_low_income_2010_after) frac_low_income_2010 after, fe robust
		eststo
		estadd local FixedEffect "College"
	xtset state_year
	xi: xtivreg2 d_ln_rev_x_inv (d_ln_fteug = frac_low_income_2010_after) frac_low_income_2010 after, fe robust
		eststo
		estadd local FixedEffect "State-year"
	xtset opeid6 awardyear
	esttab using ./Tables/Table8.tex, replace ///
		star(* 0.05 ** 0.01 *** 0.001) ///
		noomitted ///
		booktabs ///
		se ///
        	stats(FixedEffect N, labels("Fixed Effect" "Obs.")) ///
		mtitles($\Delta$\-Ln(Revenues) $\Delta$\-Ln(Revenues) $\Delta$\-Ln(Revenues)) ///
		eqlabels(none) ///
		keep(d_ln_fteug) ///
		varlabels(	d_ln_fteug "$\Delta$\-Ln(UFTEs)" )

	* Table 9
		eststo clear
	xi: reg d_ugrad_plus_volloans i.after*frac_low_income_2010, cluster(opeid6)
		eststo
	xi: reg d_fteug i.after*frac_low_income_2010, cluster(opeid6)
		eststo
	xi: reg d_total_revenues i.after*frac_low_income_2010, cluster(opeid6)
		eststo
	xi: reg d_total_expenses i.after*frac_low_income_2010, cluster(opeid6)
		eststo
	esttab using ./Tables/Table9.tex, replace ///
		star(* 0.05 ** 0.01 *** 0.001) ///
		noomitted ///
		booktabs ///
		se ///
        	stats(r2 N, labels("$ R^2$" "Obs.")) ///
		mtitles($\Delta$\-PLUS~vol $\Delta$\-UFTEs $\Delta$\-Revenues $\Delta$\-Expenses) ///
		eqlabels(none) ///
		keep(_IaftXfrac__1 frac_low_income_2010 _Iafter_1 _cons ) ///
		order(_IaftXfrac__1 frac_low_income_2010 _Iafter_1 _cons ) ///
		varlabels(	_IaftXfrac__1 "Fraction $\times$ After" ///
				frac_low_income_2010 "Fraction" ///
				_Iafter_1 "After" ///
				_cons "Constant" )

	* Table 10
	xtset opeid6
		eststo clear
	xi: xtreg d_ln_ugrad_plus_volloans i.after*frac_low_income_2010, cluster(opeid6) fe
	        eststo
	xi: xtreg d_ln_fteug i.after*frac_low_income_2010, cluster(opeid6) fe
	        eststo
	xi: xtreg d_ln_rev_x_inv i.after*frac_low_income_2010, cluster(opeid6) fe
	        eststo
	xi: xtreg d_ln_total_expenses i.after*frac_low_income_2010, cluster(opeid6) fe
		eststo
	esttab using ./Tables/Table10.tex, replace ///
		star(* 0.05 ** 0.01 *** 0.001) ///
		noomitted ///
		booktabs ///
		se ///
        	stats(r2 N, labels("$ R^2$" "Obs.")) ///
		mtitles($\Delta$\-Ln(PLUS~vol) $\Delta$\-Ln(UFTEs) $\Delta$\-Ln(Revenues) $\Delta$\-Ln(Expenses)) ///
		eqlabels(none) ///
		keep(_IaftXfrac__1 _Iafter_1 _cons ) ///
		order(_IaftXfrac__1 _Iafter_1 _cons ) ///
		varlabels(	_IaftXfrac__1 "Fraction $\times$ After" ///
				_Iafter_1 "After" ///
				_cons "Constant" )

	* Table 11
		eststo clear
	xi: areg d_ln_ugrad_plus_volloans i.after*frac_low_income_2010, cluster(opeid6) absorb(state_year)
	        eststo
	xi: areg d_ln_fteug i.after*frac_low_income_2010, cluster(opeid6) absorb(state_year)
	        eststo
	xi: areg d_ln_rev_x_inv i.after*frac_low_income_2010, cluster(opeid6) absorb(state_year)
	        eststo
	xi: areg d_ln_total_expenses i.after*frac_low_income_2010, cluster(opeid6) absorb(state_year)
		eststo
	esttab using ./Tables/Table11.tex, replace ///
		star(* 0.05 ** 0.01 *** 0.001) ///
		noomitted ///
		booktabs ///
		se ///
        	stats(r2 N, labels("$ R^2$" "Obs.")) ///
		mtitles($\Delta$\-Ln(PLUS~vol) $\Delta$\-Ln(UFTEs) $\Delta$\-Ln(Revenues) $\Delta$\-Ln(Expenses)) ///
		eqlabels(none) ///
		keep(_IaftXfrac__1 frac_low_income_2010 _cons ) ///
		order(_IaftXfrac__1 frac_low_income_2010 _cons ) ///
		varlabels(	_IaftXfrac__1 "Fraction $\times$ After" ///
				frac_low_income_2010 "Fraction" ///
				_cons "Constant" )

	* Table 12
		eststo clear
	xi: reg d_ln_pell_recipients i.after*frac_low_income_2010, cluster(opeid6)
		eststo
	xi: reg d_ln_pell_disbursements i.after*frac_low_income_2010, cluster(opeid6)
		eststo
	esttab using ./Tables/Table12.tex, replace ///
		star(* 0.05 ** 0.01 *** 0.001) ///
		noomitted ///
		booktabs ///
		se ///
        	stats(r2 N, labels("$ R^2$" "Obs.")) ///
		mtitles($\Delta$\-Ln(Pell~num) $\Delta$\-Ln(Pell~vol) $\Delta$\-Ln(Pell~vol+PLUS~vol)) ///
		eqlabels(none) ///
		order(_IaftXfrac__1 frac_low_income_2010 _Iafter_1 _cons ) ///
		varlabels(	_IaftXfrac__1 "Fraction $\times$ After" ///
				frac_low_income_2010 "Fraction" ///
				_Iafter_1 "After" ///
				_cons "Constant" )

	* Table 13: Summary statistics on for-profit and non-profit schools
		* Label variables
			label variable fteug "\quad Undergraduate FTEs"
			label variable rev_x_inv "\quad Non-investment revenues (\$\\\\$ 1000\$)"
			label variable total_expenses "\quad Total expenses (\$\\\\$ 1000\$)"
			label variable chg1ay3 "\quad Advertised tuition and fees (\$\\\\$ 1000\$)"
			label variable rev_x_inv_fteug "\quad Non-investment revenues / UFTEs (\$\\\\$ 1000\$)"
			label variable ugrad_plus_numreps_efytotlt "\quad Fraction of students receiving PLUS loans"
			label variable tuition_fees_s "\quad\quad Frac from tuition and fees"
			label variable auxent_revenue_s "\quad\quad Frac from aux. enterprises"
			label variable fedl_apgtcx_s "\quad\quad Frac from federal grants/contracts"
			label variable pvgifts_grants_contracts_s "\quad\quad Frac from priv gifts, grants, contracts"
			label variable statelocal_apgtcx_s "\quad\quad Frac from state/local grants, contracts"
			label variable other_revenue_s "\quad\quad Frac from other revenues"
			label variable frac_low_income "\quad Frac of aid recipients less than \$ \\\\$ 48\$~k income" // (F\\textsubscript{i,2010})"
			label variable total_expenses_fteug "\quad Total expenses / UFTEs (\$\\\\$ 1000\$)"
		* Save the list of summary statistics to display.
			local sumvars fteug rev_x_inv total_expenses chg1ay3 rev_x_inv_fteug ///
				tuition_fees_s auxent_revenue_s fedl_apgtcx_s pvgifts_grants_contracts_s statelocal_apgtcx_s other_revenue_s ///
	 			total_expenses_fteug frac_low_income
		* Build the table of summary statistics (using external calls to Bash shell)
			!echo "\begin{tabular}{l c c c c c c}" > ./Tables/Table13.tex
			!echo "\toprule Variable description & Obs & Q25 & Median & Q75 & Mean & Std dev \\\\ \hline \\\\[-1.8ex]" >> ./Tables/Table13.tex
			foreach category in nonprofit forprofit {
				if "`category'" == "nonprofit" {
					!echo "Non-profit: \\\\ " >> ./Tables/Table13.tex
					local for_profit_dummy_value = 0
				}
				if "`category'" == "forprofit" {
					!echo "\hline \\\\[-1.8ex] For-profit: \\\\ " >> ./Tables/Table13.tex	
					local for_profit_dummy_value = 1
				}
			foreach compvar in `sumvars' {
				quiet sum `compvar' if forprofit == `for_profit_dummy_value' & awardyear == 2010, detail
				local p25 = r(p25)
				local median = r(p50)
				local mean = r(mean)
				local p75 = r(p75)
				local sd = r(sd)
				local N = r(N)
				if regexm("`compvar'","ln|_ratio|_fteug|_efytotlt|frac_|chg1ay3|_s") local displayformat "%10.3fc"
				else local displayformat "%10.0fc"
				!echo "`:var label `compvar'' & `:di %10.0fc `N'' & `:di `displayformat' `p25'' & `:di `displayformat' `median'' & `:di `displayformat' `p75'' & `:di `displayformat' `mean'' & `:di `displayformat' `sd'' \\\\" >> ./Tables/Table13.tex
			}
			}
			!echo "\bottomrule \end{tabular}" >> ./Tables/Table13.tex

	* Table 14
		eststo clear
	xi: reg d_ln_fteug i.after*frac_low_income_2010 if forprofit == 0, cluster(opeid6)
		eststo
	xi: reg d_ln_efytotlt i.after*frac_low_income_2010 if forprofit == 0, cluster(opeid6)
		eststo
	xi: reg d_ln_rev_x_inv i.after*frac_low_income_2010 if forprofit == 0, cluster(opeid6)
		eststo
	xi: reg d_ln_total_expenses i.after*frac_low_income_2010 if forprofit == 0, cluster(opeid6)
		eststo
	esttab using ./Tables/Table14.tex, replace ///
		star(* 0.05 ** 0.01 *** 0.001) ///
		noomitted ///
		booktabs ///
		se ///
        	stats(r2 N, labels("$ R^2$" "Obs.")) ///
		mtitles($\Delta$\-Ln(UFTEs) $\Delta$\-Ln(Headcount) $\Delta$\-Ln(Revenues) $\Delta$\-Ln(Expenses)) ///
		eqlabels(none) ///
		order(_IaftXfrac__1 frac_low_income_2010 _Iafter_1 _cons ) ///
		varlabels(	_IaftXfrac__1 "Fraction $\times$ After" ///
				frac_low_income_2010 "Fraction" ///
				_Iafter_1 "After" ///
				_cons "Constant" )

	* Table 15
		eststo clear
	xi: reg d_ln_fteug i.after*frac_low_income_2010 if forprofit == 1, cluster(opeid6)
		eststo
	xi: reg d_ln_efytotlt i.after*frac_low_income_2010 if forprofit == 1, cluster(opeid6)
		eststo
	xi: reg d_ln_rev_x_inv i.after*frac_low_income_2010 if forprofit == 1, cluster(opeid6)
		eststo
	xi: reg d_ln_total_expenses i.after*frac_low_income_2010 if forprofit == 1, cluster(opeid6)
		eststo
	esttab using ./Tables/Table15.tex, replace ///
		star(* 0.05 ** 0.01 *** 0.001) ///
		noomitted ///
		booktabs ///
		se ///
        	stats(r2 N, labels("$ R^2$" "Obs.")) ///
		mtitles($\Delta$\-Ln(UFTEs) $\Delta$\-Ln(Headcount) $\Delta$\-Ln(Revenues) $\Delta$\-Ln(Expenses)) ///
		eqlabels(none) ///
		order(_IaftXfrac__1 frac_low_income_2010 _Iafter_1 _cons ) ///
		varlabels(	_IaftXfrac__1 "Fraction $\times$ After" ///
				frac_low_income_2010 "Fraction" ///
				_Iafter_1 "After" ///
				_cons "Constant"  )

	* Table 16
		eststo clear
	xi: ivreg2 d_ln_total_expenses (d_ln_fteug = frac_low_income_2010_after) frac_low_income_2010 after if forprofit == 0, cluster(opeid6)
		eststo
		estadd local ForProfit "Non-profit"
	xi: ivreg2 d_ln_total_expenses (d_ln_fteug = frac_low_income_2010_after) frac_low_income_2010 after if forprofit == 1, cluster(opeid6)
		eststo
		estadd local ForProfit "For-profit"
	xi: ivreg2 d_ln_rev_x_inv (d_ln_fteug = frac_low_income_2010_after) frac_low_income_2010 after if forprofit == 0, cluster(opeid6)
		eststo
		estadd local ForProfit "Non-profit"
	xi: ivreg2 d_ln_rev_x_inv (d_ln_fteug = frac_low_income_2010_after) frac_low_income_2010 after if forprofit == 1, cluster(opeid6)
		eststo
		estadd local ForProfit "For-profit"
	esttab using ./Tables/Table16.tex, replace ///
		star(* 0.05 ** 0.01 *** 0.001) ///
		noomitted ///
		booktabs ///
		se ///
        	stats(ForProfit N, labels("School type" "Obs.")) ///
		mtitles($\Delta$\-Ln(Expenses) $\Delta$\-Ln(Expenses) $\Delta$\-Ln(Revenues) $\Delta$\-Ln(Revenues)) ///
		eqlabels(none) ///
		keep(d_ln_fteug) ///
		varlabels(	d_ln_fteug "$\Delta$\-Ln(UFTEs)" )

**********************************
* Basic accounting figures
**********************************

	* Figures reporting aggregate revenues (net of investment return), aggregate expenses, change in aggregate equity, and aggregate investment return
	* cntlaffi: 2=for-profit, 3=non-religious,private,non-profit, 4=religious,private,non-profit
		use ./Data/IPEDS/IPEDS if inrange(awardyear,2002,2018) & inlist(cntlaffi,2,3,4), clear 
		g equity = total_equity if cntlaffi == 2
		replace equity = net_assets if inlist(cntlaffi,3,4)
		keep awardyear equity investment_return total_revenues total_expenses
		bysort awardyear: egen agg_equity = sum(equity)
		bysort awardyear: egen agg_investment_return = sum(investment_return)
		bysort awardyear: egen agg_revenues = sum(total_revenues)
		bysort awardyear: egen agg_expenses = sum(total_expenses)
		by awardyear: keep if _n == 1
		g agg_net_revenues = agg_revenues - agg_investment_return
		line agg_equity awardyear , ylabel(0 "0" 2e11 "200" 4e11 "400" 6e11 "600" 8e11 "800") ytitle("Billions of dollars") xlabel(2002(3)2018) xtitle("Award year") graphregion(color(white)) legend(order(1 "Aggregate equity or net assets"))
		graph export ./Figures/aggregate_equity_IPEDS.eps, replace
		line agg_net_revenues agg_expenses awardyear, ylabel(0 "0" 10e10 "100" 20e10 "200") ytitle("Billions of dollars") xlabel(2002(3)2018) xtitle("Award year") graphregion(color(white)) legend(order(1 "Total revenues, net of investment income" 2 "Total expenses") rows(2)) lpattern(solid dash dash_dot dot) lcolor(black black black black)
		graph export ./Figures/FigureB1a.eps, replace
		tsset awardyear
		g d_agg_equity = d.agg_equity
		keep if awardyear >= 2003
		line agg_investment_return d_agg_equity awardyear , ylabel(-10e10 "-100" -5e10 "-50" 0 "0" 5e10 "50" 10e10 "100") ytitle("Billions of dollars") xlabel(2002(3)2018) xtitle("Award year") graphregion(color(white)) legend(order(1 "Investment return" 2 "Change in equity or net assets")) lpattern(solid dash dash_dot dot) lcolor(black black black black)
		graph export ./Figures/FigureB1b.eps, replace

	* Figure breaking down the categories of total revenues:
		use ./Data/IPEDS/IPEDS if inrange(awardyear,2002,2018) & inlist(cntlaffi,2,3,4), clear 
		foreach var of varlist `revenue_vars' {
			if "`var'" == "investment_return" continue
			rename `var' `var'_i
			bysort awardyear: egen `var' = sum(`var'_i)
		}
		keep awardyear `revenue_vars'
		bysort awardyear: keep if _n == 1
		g helper2 = 0
		local levels ""
		foreach var of varlist `revenue_vars' {
			if "`var'" == "investment_return" continue
			g `var'_c = `var' + helper2
			replace helper2 = `var'_c
			local levels = "`var'_c `levels'"
		}
		label variable tuition_fees_c "Tuition/fees"
		label variable auxent_revenue_c "Aux ent"
		label variable fedl_apgtcx_c "Fed'l govt"
		label variable statelocal_apgtcx_c "State & local govt"
		label variable pvgifts_grants_contracts_c "Private sources"
		label variable educational_sales_c "Ed'l sales"
		label variable hospital_revenue_c "Hospital"
		label variable affiliate_contributions_c "Aff cntrbtns"
		label variable independent_ops_revenue_c "Ind. ops"
		label variable other_revenue_c "Other"
		twoway ( area `levels' awardyear, legend(position(6) cols(3)) ylabel(0 "0" 1e11 "100" 2e11 "200") ytitle("Billions of dollars") yscale(titlegap(2)) xlabel(2002(3)2018) xtitle("Award year") graphregion(color(white)) )
		graph export ./Figures/FigureB2a.eps, replace

	* Figure breaking down the categories of total expenses:
		use ./Data/IPEDS/IPEDS if inrange(awardyear,2002,2018) & inlist(cntlaffi,2,3,4), clear 
		foreach var of varlist `expense_vars' {
			rename `var' `var'_i
			bysort awardyear: egen `var' = sum(`var'_i)
		}
		keep awardyear `expense_vars'
		bysort awardyear: keep if _n == 1
		g helper2 = 0
		local levels ""
		foreach var of varlist `expense_vars' {
			* The "plant operations and expense" category is always zero in IPEDS.
			* If included in the aggregate figures, this misleadingly suggests that schools spend nothing on this category.
			* The more likely explanation is that the figures are also recorded somewhere else, but we have not seen any clear explanation of this.
			* Therefore we do not aggregate this category into any other when building the data,
			* but we will explicitly skip over it when constructing the figures in this section.
			if "`var'" == "plant_expense" continue 
			g `var'_c = `var' + helper2
			replace helper2 = `var'_c
			local levels = "`var'_c `levels'"
		}
		label variable instrl_expense_c "Instruction"
		label variable rsrch_svc_expense_c "Rsrch, svc"
		label variable support_expense_c "Supp, student svc"
		label variable auxent_expense_c "Aux ent"
		label variable netgrantaid_expense_c "Net grant aid"
		label variable hospsvc_expense_c "Hospital"
		label variable indops_expense_c "Ind. ops"
		label variable other_expense_c "Other"
		twoway (area `levels' awardyear, legend(position(6) cols(3)) ylabel(0 "0" 1e11 "100" 2e11 "200") ytitle("Billions of dollars") yscale(titlegap(2)) xlabel(2002(3)2018) xtitle("Award year") graphregion(color(white)) )
		graph export ./Figures/FigureB2b.eps, replace

	* Table of shares of each category of revenues and expenses
		use ./Data/IPEDS/IPEDS if inrange(awardyear,2002,2018) & inlist(cntlaffi,2,3,4), clear 
		label variable tuition_fees "Tuition and fees"
		label variable auxent_revenue "Auxiliary enterprises"
		label variable fedl_apgtcx "Federal appropriations/grants/contracts"
		label variable statelocal_apgtcx "State/local appropriations/grants/contracts"
		label variable pvgifts_grants_contracts "Private gifts/grants/contracts"
		label variable educational_sales "Sales of educational services"
		label variable hospital_revenue "Hospital revenues"
		label variable affiliate_contributions "Contributions from affiliate entities"
		label variable investment_return "Investment return"
		label variable independent_ops_revenue "Independent operations"
		label variable other_revenue "Other revenues"
		label variable instrl_expense "Instructional"
		label variable auxent_expense "Auxiliary enterprises"
		label variable support_expense "Support and student services"
		label variable rsrch_svc_expense "Research and public service"
		label variable hospsvc_expense "Hospital"
		label variable netgrantaid_expense "Net grant aid"
		label variable plant_expense "Plant operation/maintenance"
		label variable indops_expense "Independent operations"
		label variable other_expense  "Other expenses"
		!echo "\begin{tabular}{l c c c c c c}" > ./Tables/TableB1.tex
		!echo "\toprule Variable description & Obs & Q25 & Median & Q75 & Mean & Std dev \\\\ \hline \\\\[-1.8ex]" >> ./Tables/TableB1.tex
		g rev_x_inv = total_revenues - investment_return
		* There are 5 observations with exactly $1 of non-investment revenue; round this down to zero so they don't have undue influence on the shares I calculate.
		* The next-smallest value of non-investment revenue is $444.
		replace rev_x_inv = 0 if rev_x_inv == 1 
		foreach var in `revenue_vars' `expense_vars' {
			if "`var'" == "investment_return" continue
			if "`var'" == "plant_expense" continue 
			replace `var' = 0 if `var' == .
		}
		foreach var in `revenue_vars' {
			if "`var'" == "investment_return" continue
			g `var'_s = `var' / rev_x_inv
		}
		foreach var in `expense_vars' {
			if "`var'" == "plant_expense" continue 
			g `var'_s = `var' / total_expenses
		}
		foreach var in rev `revenue_vars' hline exp `expense_vars' {
			if "`var'" == "investment_return" continue
			if "`var'" == "plant_expense" continue 
			if "`var'" == "rev" {
				!echo "Shares of non-investment revenues: \\\\" >> ./Tables/TableB1.tex
				continue
			}
			if "`var'" == "hline" {
				!echo "\hline \\\\[-1.8ex] " >> ./Tables/TableB1.tex
				continue
			}
			if "`var'" == "exp" {
				!echo "Shares of total expenses: \\\\" >> ./Tables/TableB1.tex
				continue
			}
			quiet sum `var'_s, detail
			local p25 = r(p25)
			local median = r(p50)
			local mean = r(mean)
			local p75 = r(p75)
			local sd = r(sd)
			local N = r(N)
			local displayformat "%10.3fc"
			!echo "\quad `:var label `var'' & `:di %10.0fc `N'' & `:di `displayformat' `p25'' & `:di `displayformat' `median'' & `:di `displayformat' `p75'' & `:di `displayformat' `mean'' & `:di `displayformat' `sd'' \\\\" >> ./Tables/TableB1.tex
		}
		!echo "\bottomrule \end{tabular}" >> ./Tables/TableB1.tex
